<?php

App::import('Vendor', 'ClassEzpdf', array('file' => 'pdf/class.ezpdf.php'));
App::import('Vendor', 'EnLetras', array('file' => 'EnLetras.class.php'));
App::import('model', 'Appraisal');

//busqueda de información de avaluo
$avaluo = new Appraisal();
$avaluo->create();
$avaluo->recursive = -1;
$avaluoActual = $avaluo->find('first', array('conditions' => array('Appraisal.id' => $id)));

//Creación de la cadena con los departamentos de cada predio que esta en este avaluo.
App::import('model', 'Property');
App::import('model', 'Departament');
$proyecto = $avaluoActual['Appraisal']['proyect_id'];


$p = new Property();
$d = new Departament();
$p->recursive = 0;
//seleccionar solo los campos que se necesitan
$predios = $p->find('all', array('conditions' => array('Property.proyect_id' => $proyecto), 'fields' => array('City.departament_id', 'City.name', 'City.id', 'Property.vereda', 'Property.nombre')));

$departamentos = "";
$ciudades = "";
$veredas = "";
$nombrePredios = "";
$destinacionesActuales = "";
$panterior = "";
$danterior = "";
$vanterior = "";

foreach ($predios as $predio) {

    $dep = $d->field('name', array('Departament.id' => $predio['City']['departament_id']));

    if ($panterior != $predio['City']['name']) {
        $ciudades .= $predio['City']['name'] . ", ";
    }if ($danterior != $dep) {
        $departamentos .= $dep . ", ";
    }
    if (!ereg($predio['Property']['vereda'], $veredas)) {
        $veredas .= $predio['Property']['vereda'] . ", ";
    }

    $danterior = $dep;
    $panterior = $predio['City']['name'];
    $nombrePredios .= $predio['Property']['nombre'] . ", ";
}





$pdf = new Cezpdf('LETTER');
$pdf->ezStartPageNumbers(20, 55, 10, 'right', utf8_decode('Página' . "  {PAGENUM} de {TOTALPAGENUM}"), 1);
generar_carta(' ', "", $pdf);


$str = "<b>AVALUO COMERCIAL RURAL</b> \n";
$pdf->ezText(utf8_decode($str), 12, array('justification' => 'center'));
$data = array();
$data[] = array('numero' => "1 .", 'nombre' => utf8_decode("<b>INFORMACIÓN BASICA</b>"));
//el tercer parametro es el nombre de la tabla.
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('numero' => array('width' => 50, 'justification' => 'full'), 'nombre' => array('width' => 450, 'justification' => 'full')),
        )
);

$data = array();
$data[] = array('numero' => "1.1", 'nombre' => utf8_decode("SOLICITANTE"), 'informacion' => "INCODER");
$data[] = array('numero' => "1.2", 'nombre' => utf8_decode("RADICACIÓN"), 'informacion' => utf8_decode($avaluoActual['Appraisal']['radicacion']));
$data[] = array('numero' => "1.3", 'nombre' => utf8_decode("FECHA RADICACIÓN"), 'informacion' => $avaluoActual['Appraisal']['fecha_radicacion']);
$data[] = array('numero' => "1.4", 'nombre' => utf8_decode("TIPO DE INMUEBLE"), 'informacion' => utf8_decode($avaluoActual['Appraisal']['tipo_inmueble']));
$data[] = array('numero' => "1.5", 'nombre' => utf8_decode("TIPO DE AVALÚO"), 'informacion' => 'COMERCIAL RURAL');
$data[] = array('numero' => "1.6", 'nombre' => utf8_decode("DESTINACIÓN ACTUAL"), 'informacion' => utf8_decode($avaluoActual['Appraisal']['destinacion_actual']));
$data[] = array('numero' => "1.7", 'nombre' => utf8_decode("DEPARTAMENTO"), 'informacion' => utf8_decode($departamentos));
$data[] = array('numero' => "1.8", 'nombre' => utf8_decode("MUNICIPIO"), 'informacion' => utf8_decode($ciudades));
$data[] = array('numero' => "1.9", 'nombre' => utf8_decode("VEREDA"), 'informacion' => utf8_decode($veredas));
$data[] = array('numero' => "1.10", 'nombre' => utf8_decode("NOMBRE DEL PREDIO O MEJORA"), 'informacion' => utf8_decode($nombrePredios));
$data[] = array('numero' => "1.11", 'nombre' => utf8_decode("MARCO JURÍDICO"), 'informacion' => 'Le1 160 de 1994 decreto 2000 de 2009');
$data[] = array('numero' => "1.12", 'nombre' => utf8_decode("PLANCHA IGAC"), 'informacion' => utf8_decode($avaluoActual['Appraisal']['plancha_igac']));
$data[] = array('numero' => "1.13", 'nombre' => utf8_decode("FECHA DE ASIGNACIÓN Y VISITA"), 'informacion' => utf8_decode($avaluoActual['Appraisal']['fecha_asignacion'] . ", " . $avaluoActual['Appraisal']['fecha_visita']));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('numero' => array('width' => 50, 'justification' => 'full'), 'nombre' => array('width' => 150, 'justification' => 'full'), 'informacion' => array('width' => 300, 'justification' => 'full')),
        )
);

///////////////////////////////////    2     /////////////////////////////////////////////

$str = "\n";
$pdf->ezText(utf8_decode($str));

$data = array();
$data[] = array('numero' => "2 .", 'nombre' => utf8_decode("<b>INFORMACIÓN CATASTRAL</b>"));
//el tercer parametro es el nombre de la tabla.
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('numero' => array('width' => 70, 'justification' => 'full'), 'nombre' => array('width' => 430, 'justification' => 'center')),
        )
);

///2.INFORMACION CATASTRAL 
$globalizado = $p->PropertyAppraisal->find('count', array('conditions' => array('PropertyAppraisal.appraisal_id' => $id, 'PropertyAppraisal.avaluo_globalizado' => 1)));

$data = array();
$data_zonas=array();
$predios = $p->PropertyAppraisal->find('all', array('conditions' => array('PropertyAppraisal.appraisal_id' => $id), 'order' => array('Property.id ASC'), 'fields' => array('Property.id', 'Property.np_departamento', 'Property.np_municipio', 'Property.np_tipo', 'Property.np_vereda', 'Property.np_predio', 'Property.np_mejora', 'Property.matricula', 'PropertyAppraisal.id', 'PropertyAppraisal.matricula', 'PropertyAppraisal.propietarios', 'PropertyAppraisal.area_levantamiento', 'Property.nombre' , 'PropertyAppraisal.titulo', 'PropertyAppraisal.servidumbre', 'PropertyAppraisal.vigencia_actualizacion', 'PropertyAppraisal.avaluo_vigente','PropertyAppraisal.observaciones', 'Property.codigo')));
$data[] = array('codigo' => utf8_decode('CÓDIGO'), 'vigencia' => utf8_decode('VIGENCIA DE LA ACTUALIZACIÓN'), 'descripcion' => utf8_decode('OBSERVACIONES'), 'avaluo' => utf8_decode('AVALUÓ VIGENTE'));
$data_zonas[]=array('predio'=>'PREDIO', 'codigo'=>utf8_decode('CÓDIGO'),'areat'=>utf8_decode('ÁREA TERRENO (ha)'),'areac'=>utf8_decode('ÁREA CONSTRUCCIÓN(m2)'),'descripcion'=>utf8_decode('DESCRIPCIÓN'),'valor'=>utf8_decode('VALOR') ) ;
App::Import('model','UniformZone');
$zn=new UniformZone();
$zn->recursive=-1;
foreach ($predios as $predio) {
    $npredial = $predio['Property']['np_departamento'] . "-" . $predio['Property']['np_municipio'] . "-" . $predio['Property']['np_tipo'] . "-" . $predio['Property']['np_vereda'] . "-" . $predio['Property']['np_vereda'] . "-" . $predio['Property']['np_predio'] . "-" . $predio['Property']['np_mejora'];
    $data[] = array('codigo' => utf8_decode($predio['Property']['codigo']."\n$npredial"), 'vigencia' => utf8_decode($predio['PropertyAppraisal']['vigencia_actualizacion']), 'descripcion' => utf8_decode($predio['PropertyAppraisal']['observaciones']), 'avaluo' => '$' . number_format($predio['PropertyAppraisal']['avaluo_vigente'], 0, ",", "."));
    $zonas=$zn->find('all',array('conditions'=>array('UniformZone.property_id'=>$predio['Property']['id'])));
    foreach ($zonas as $zona) {
      $data_zonas[]=array('predio'=>$predio['Property']['codigo']."\n$npredial",'codigo'=>utf8_decode($zona['UniformZone']['codigo']),'areat'=>$zona['UniformZone']['area_terreno'],'areac'=>$zona['UniformZone']['area_construccion'],'descripcion'=>utf8_decode($zona['UniformZone']['descripcion']),'valor'=>'$' . number_format($zona['UniformZone']['valor'], 0, ",", ".") ) ;
    }
}

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
     'cols' => array('codigo' => array('width' => 150, 'justification' => 'full')),
        )
);


//zonas homogeneas
//
//
$data = array();
$data[] = array('numero' => "", 'nombre' => utf8_decode("ZONAS HOMOGÉNEAS"));
//el tercer parametro es el nombre de la tabla.
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('numero' => array('width' => 70, 'justification' => 'full'), 'nombre' => array('width' => 430, 'justification' => 'center')),
        )
);
$pdf->ezTable(
        $data_zonas, null,null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('codigo' => array('width' => 70, 'justification' => 'full')),
        )
);
//OBSERVACIONES 
//
//
//
if ($avaluoActual['Appraisal']['observaciones']!="") {
    $data = array();
    $data[] = array('docs' => 'OBSERVACIONES', 'observaciones' =>$avaluoActual['Appraisal']['observaciones']);

    $pdf->ezTable(
            $data, null, null, array(
        'fontSize' => 8,
        'titleFontSize' => 12,
        'width' => 500,
        'showHeadings' => 0,
        'showLines' => 2,
        'shaded' => 0,
        'cols' => array('docs' => array('width' => 80, 'justification' => 'full'), 'observaciones' => array('width' => 420, 'justification' => 'full')),
            )
    );
}

///ZONAS HOMOGENEAS


//fin informacion catastral
//3.DOCUMENTOS SUMINISTRADOS

$pdf->ezText('', 12, array('justification' => 'center'));
$data = array();
$data[] = array('docs' => '<b>3.DOCUMENTOS SUMINISTRADOS</b>');
$data[] = array('docs' => utf8_decode($avaluoActual['Appraisal']['documentos_suministrados']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('docs' => array('width' => 500, 'justification' => 'full')),
        )
);
//4 .TITULACIÓN E INFORMACIÓN JURÍDICA

$pdf->ezText('', 12, array('justification' => 'center'));
$data = array();
$data[] = array('num' => '4', 'contenido' => utf8_decode('<b>TITULACIÓN E INFORMACIÓN JURÍDICA</b>'));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);



$data = array();
$data[] = array('codigo' => utf8_decode('CÓDIGO'), 'prop' => utf8_decode('PROPIETARIO'), 'titulo' => utf8_decode('TÍTULO DE ADQUISICIÓN'), 'matricula' => utf8_decode('MATRÍCULA'), 'servidumbre' => utf8_decode('SERVIDUMBRE'));
$res = "";
foreach ($predios as $predio) {
    switch ($predio['PropertyAppraisal']['servidumbre']) {
        case 1:
            $res = "Si";
            break;
        case 0:
            $res = "No";
            break;
        default:
            break;
    }
    
    $data[] = array('codigo' => utf8_decode($predio['Property']['codigo'] ), 'prop' => utf8_decode($predio['PropertyAppraisal']['propietarios']), 'titulo' => utf8_decode($predio['PropertyAppraisal']['titulo']), 'matricula' => utf8_decode($predio['PropertyAppraisal']['matricula']), 'servidumbre' => $res);

    if ($globalizado > 0)
        break;
}

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('codigo' => array('width' => 130, 'justification' => 'full'), 'prop' => array('width' => 135, 'justification' => 'full'), 'titulo' => array('width' => 105, 'justification' => 'full'), 'matricula' => array('width' => 70, 'justification' => 'full'), 'servidumbre' => array('width' => 60, 'justification' => 'center')),
        )
);

$pdf->ezText(utf8_decode('NOTA : LA ANTERIOR INFORMACIÓN NO CONSTITUYE ESTUDIO JURÍDICO.'), 12, array('justification' => 'center'));
///////////////5.DESCRIPCION DEL SECTOR
//
$pdf->ezText('', 12, array('justification' => 'center'));
$data = array();
$data[] = array('num' => '5.', 'contenido' => utf8_decode('<b>DESCRIPCIÓN GENERAL DEL SECTOR</b>'));
$data[] = array('num' => '5.1', 'contenido' => utf8_decode('<b>DELIMITACION DEL SECTOR</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['delimitacion_sector']));
$data[] = array('num' => '5.2', 'contenido' => utf8_decode('<b>ACTIVIDAD PREDOMINANTE</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['actividad_predominante']));
$data[] = array('num' => '5.3', 'contenido' => utf8_decode('<b>DESARROLLO</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['desarrollo']));
$data[] = array('num' => '5.4', 'contenido' => utf8_decode('<b>NIVEL SOCIOECONÓMICO</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['nivel_socio_economico']));
$data[] = array('num' => '5.5', 'contenido' => utf8_decode('<b>COMERCIALIZACIÓN</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['comercializacion']));
$data[] = array('num' => '5.6', 'contenido' => utf8_decode('<b>VIAS DE ACCESO Y CARACTERÍSTICAS</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['vias_acceso']));
$data[] = array('num' => '5.7', 'contenido' => utf8_decode('<b>SERVICIOS COMUNALES</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['servicios_comunales']));
$data[] = array('num' => '5.8', 'contenido' => utf8_decode('<b>SERVICIOS PÚBLICOS</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['servicios_publicos']));
$data[] = array('num' => '5.9', 'contenido' => utf8_decode('<b>ORDEN PÚBLICO</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['orden_publico']));
$data[] = array('num' => '5.10', 'contenido' => utf8_decode('<b>PERSPECTIVAS DE VALORIZACIÓN</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['perspectivas_valorizacion']));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

//
////////////FIN DESCRIPCION DEL SECTOR
//6.REGLAMENTACION URBANISTICA
$pdf->ezText('', 12, array('justification' => 'center'));
$data = array();
$data[] = array('num' => '6', 'contenido' => utf8_decode('<b>REGLAMENTACIÓN URBANISTICA</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['reglamentacion_urbanistica']));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
//FIN REGLAMENTACION URBANISTICAç
///7.DESCRIPCION DEL INMUEBLE



$pdf->ezText('', 12, array('justification' => 'center'));
$data = array();
$data[] = array('num' => '7', 'contenido' => utf8_decode('<b>DESRIPCICIÓN DEL INMUEBLE</b>'));
$data[] = array('num' => '', 'contenido' => '');
$data[] = array('num' => '7.1', 'contenido' => utf8_decode('<b>CARACTERÍSTICAS GENERALES DEL TERRENO</b>'));
//vias alternas traido de la encuesta
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);


$data = array();
$data[] = array('num' => '', 'medio' => utf8_decode("<b>UBICACIÓN</b>$str"), 'contenido' => utf8_decode($avaluoActual['Appraisal']['ubicacion']));


$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'medio' => array('width' => 70, 'justification' => 'full'), 'contenido' => array('width' => 380, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array( 'medio' => utf8_decode("<b>DISTANCIA EN KILÓMETROS A PARTIR DE LA TERMINACIÓN DEL PERÍMETRO URBANO DE LA CIUDAD CAPITAL</b>$str"), 'contenido' => utf8_decode($avaluoActual['Appraisal']['distancia_perimetro_urbano']));


$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'medio' => array('width' => 70, 'justification' => 'full'), 'contenido' => array('width' => 380, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));




$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>ÁREAS</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 70, 'justification' => 'full'), 'contenido' => array('width' => 430, 'justification' => 'full')),
        )
);
$data = array();
$areatot = 0;
$data[] = array('codigo' => utf8_decode('CÓDIGO'), 'nombre' => utf8_decode('NOMBRE'), 'areal' => utf8_decode('ÁREA LEVANTAMIENTO (ha.)'));

foreach ($predios as $predio) {
    $data[] = array('codigo' => utf8_decode($predio['Property']['codigo']), 'nombre' => utf8_decode($predio['Property']['nombre']), 'areal' => utf8_decode($predio['PropertyAppraisal']['area_levantamiento']));
    $areatot+=$predio['PropertyAppraisal']['area_levantamiento'];
   // echo   $predio['PropertyAppraisal']['area_levantamiento'].$predio['Property']['codigo']."<br>";
    if ($globalizado > 0)
        break;
}

$data[] = array('codigo' => utf8_decode(''), 'nombre' => utf8_decode('TOTAL (ha):'), 'areal' => utf8_decode($areatot));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('codigo' => array('width' => 70, 'justification' => 'full'), 'nombre' => array('width' => 75, 'justification' => 'full'), 'descripcion' => array('width' => 75, 'justification' => 'full'), 'valor' => array('width' => 70, 'justification' => 'full'), 'areat' => array('width' => 70, 'justification' => 'full'), 'areac' => array('width' => 70, 'justification' => 'full'), 'avaluo' => array('width' => 70, 'justification' => 'full')),
        )
);

$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>LINDEROS Y DIMENSIONES</b>'));
$data[] = array('num' => 'NORTE', 'contenido' => utf8_decode($avaluoActual['Appraisal']['lindero_norte']));
$data[] = array('num' => 'SUR', 'contenido' => utf8_decode($avaluoActual['Appraisal']['lindero_sur']));
$data[] = array('num' => 'ORIENTE', 'contenido' => utf8_decode($avaluoActual['Appraisal']['lindero_oriente']));
$data[] = array('num' => 'OCIDENTE', 'contenido' => utf8_decode($avaluoActual['Appraisal']['lindero_occidente']));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);


$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>CARACTERISTÍCAS CLIMÁTICAS</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$data = array();
$data[] = array('max' => utf8_decode('ALTURA MÁXIMA msnm'), 'min' => utf8_decode('ALTURA MÍNIMA PROMEDIO msnm'), 'tmax' => utf8_decode('TEMPERATURA MÁXIMA C°'), 'tmin' => utf8_decode('TEMPERATURA MÍNIMA C°'), 'tprom' => utf8_decode('TEMPERATURA PROMEDIO C°'), 'pt' => utf8_decode('PISO TÉRMICO'));

$data[] = array('max' => utf8_decode($avaluoActual['Appraisal']['altura_maxima']), 'min' => utf8_decode($avaluoActual['Appraisal']['altura_minima']), 'tmax' => utf8_decode($avaluoActual['Appraisal']['temperatura_maxima']), 'tmin' => utf8_decode($avaluoActual['Appraisal']['temperatura_minima']), 'tprom' => utf8_decode($avaluoActual['Appraisal']['temperatura_promedio']), 'pt' => utf8_decode($avaluoActual['Appraisal']['piso_termico']));

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('tmax' => array('width' => 85, 'justification' => 'full'), 'max' => array('width' => 85, 'justification' => 'full'), 'min' => array('width' => 85, 'justification' => 'full'), 'tmin' => array('width' => 85, 'justification' => 'full'), 'tmax' => array('width' => 85, 'justification' => 'full'), 'pt' => array('width' => 75, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>SUELOS</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['suelos']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>CERCAS PERIMETRALES INTERNAS</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['cercas_perimetrales_internas']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>EXPLOTACIÓN ECONÓMICA</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['explotacion_economica']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>REDES DE SERVICIOS</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['redes_de_servicios']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>IRRIGACIÓN</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['irrigacion']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
if ($avaluoActual['Appraisal']['otros'] != "") {
    $data = array();
    $data[] = array('num' => '', 'contenido' => utf8_decode('<b>OTROS</b>'));
    $data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['otros']));
    $pdf->ezTable(
            $data, null, null, array(
        'fontSize' => 8,
        'titleFontSize' => 12,
        'width' => 500,
        'showHeadings' => 0,
        'showLines' => 2,
        'shaded' => 0,
        'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
            )
    );
}

$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '', 'contenido' => utf8_decode('<b>UNIDADES FISIOGRÁFICAS</b>'));
App::Import('model', 'PhysiographicUnit');

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

$data = array();
$data_11 = array();
App::Import('model', 'PhysiographicUnit');
$unit = new PhysiographicUnit();
$unit->recursive = -1;
$cont = 1;
$unidades = $unit->find('all', array('conditions' => array('PhysiographicUnit.proyect_id' => $this->Session->read('proy_id')), 'fields' => array('PhysiographicUnit.area', 'PhysiographicUnit.clase_agrologica', 'PhysiographicUnit.valor_adoptado', 'PhysiographicUnit.descripcion', 'PhysiographicUnit.topografia_relieve')));
$data[] = array('codigo' => utf8_decode('CÓDIGO'), 'num' => utf8_decode('ÁREA (ha)'), 'contenido' => utf8_decode('CLASE AGROLÓGICA'), 'topo' => utf8_decode('TOPOGRAFÍA Y RELIEVE'), 'descripcion' => utf8_decode('DESCRIPCIÓN'));
$data_11[] = array('cont' => '', 'contenido' => utf8_decode('CLASE AGROLÓGICA'), 'valor' => utf8_decode('VALOR ADOPTADO'), 'unidad' => 'UNIDAD DE MEDIDA');
$total = array();
$valor_total = 0;
$i = 1;
$area_unidades = 0;
foreach ($unidades as $unidad) {
    $uf = "UF" . $i;
    $i++;
    $data[] = array('codigo' => $uf, 'num' => utf8_decode($unidad['PhysiographicUnit']['area']), 'contenido' => utf8_decode($unidad['PhysiographicUnit']['clase_agrologica']), 'topo' => $unidad['PhysiographicUnit']['topografia_relieve'], 'descripcion' => utf8_decode($unidad['PhysiographicUnit']['descripcion']));
    $data_11[] = array('cont' => $cont, 'contenido' => utf8_decode($unidad['PhysiographicUnit']['clase_agrologica']), 'valor' => '$' . number_format($unidad['PhysiographicUnit']['valor_adoptado'], 0, ',', '.'), 'unidad' => 'ha.' );
    $total[] = array('ITEM' =>"Clase " . $unidad['PhysiographicUnit']['clase_agrologica'], 'MAGNITUD' => $unidad['PhysiographicUnit']['area'], 'UNIDAD DE MEDIDA' => 'ha.', 'VALOR UNITARIO' => '$' . number_format($unidad['PhysiographicUnit']['valor_adoptado'], 0, ',', '.'), 'VALOR TOTAL' => ('$' . number_format($unidad['PhysiographicUnit']['area'] * $unidad['PhysiographicUnit']['valor_adoptado'], 0, ',', '.') ));
    $valor_total+=$unidad['PhysiographicUnit']['area'] * $unidad['PhysiographicUnit']['valor_adoptado'];
    $area_unidades+=$unidad['PhysiographicUnit']['area'];
    $cont++;
}

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('codigo' => array('justification' => 'full', 'width' => 50), 'num' => array('justification' => 'full', 'width' => 100), 'contenido' => array('justification' => 'full', 'width' => 80), 'descripcion' => array('justification' => 'full', 'width' => 170), 'topo' => array('justification' => 'full', 'width' => 100)),
        )
);

if ($areatot == 0 || $area_unidades == 0) {
    exit("La suma de las areas De las unidades fisiograficas o de los predios es cero, no se puede generar la carta");
} else if ($areatot != $area_unidades) {
    exit(" La suma del área de las unidades fisiográficas ($area_unidades) y la suma de las áreas del levantamiento ($areatot), son diferentes, no se puede generar el informe de avalúo");
}
//construcciones

$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2', 'contenido' => utf8_decode('<b>CARACTERÍSTICAS GENERALES DE LA CONSTRUCCIÓN</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

$data = array();
$data1 = array();
$data1[] = array('cod' => utf8_decode('PREDIO'),'num' => utf8_decode('NOMBRE DE LA CONSTRUCCIÓN'), 'contenido' => 'ESTADO');
$data2 = array();
$data2[] = array('cod' => utf8_decode('PREDIO'),'num' => utf8_decode('NOMBRE DE LA CONSTRUCCIÓN'), 'contenido' => 'VETUSTEZ');
$data3 = array();
$data3[] = array('cod' => utf8_decode('PREDIO'),'num' => utf8_decode('NOMBRE DE LA CONSTRUCCIÓN'), 'contenido' => utf8_decode('DISTRIBUCIÓN INTERNA'));
$data4 = array();
$data4[] = array('num' => utf8_decode('CÓDIGO PREDIO'), 'nombre' => utf8_decode('NOMBRE '), 'contenido' => 'MAGNITUD', 'unidad' => 'UNIDAD DE MEDIDA');
$data5 = array();
$data5[] = array('num' => utf8_decode('CÓDIGO PREDIO'), 'nombre' => utf8_decode('NOMBRE '), 'uso' => utf8_decode('DESCRIPCIÓN'), 'contenido' => 'MAGNITUD', 'unidad' => 'UNIDAD DE MEDIDA');
$data_conts = array();
$data_conts[] = array('cont' => '','pred'=>utf8_decode('CÓDIGO PREDIO'), 'nombre' => utf8_decode('NOMBRE DE LA CONSTRUCCIÓN'), 'num' => utf8_decode('VALOR ADOPTADO'), 'unidad' => 'UNIDAD DE MEDIDA');
$conteo_const = 1;
App::Import('model', 'Construction');
$cont = new Construction();
$cont->recursive = -1;

App::Import('model', 'Annex');
$anex = new Annex();
$anex->recursive = -1;
$data_anex = array();
$data_anex[] = array('cont' => '','pred'=>utf8_decode('CÓDIGO PREDIO'), 'nombre' => 'NOMBRE DEL ANEXO', 'num' => 'VALOR ADOPTADO', 'unidad' => 'UNIDAD DE MEDIDA');
$cont_anex = 1;

foreach ($predios as $predio) {

    $predio['Property']['id'];
    $construcciones = $cont->find('all', array('conditions' => array('Construction.property_id' => $predio['Property']['id'])));
    $anexos = $anex->find('all', array('conditions' => array('Annex.property_id' => $predio['Property']['id'])));

    foreach ($construcciones as $construccion) {
        $data[] = array('num' => utf8_decode('<b>NÚMERO PREDIAL</b>'), 'contenido' => utf8_decode("<b>" . $predio['Property']['codigo'] . "</b>"));
        $data[] = array('num' => utf8_decode('NOMBRE DE LA CONSTRUCCIÓN'), 'contenido' => utf8_decode($construccion['Construction']['nombre']));
        if ($construccion['Construction']['estructura'] != "")
            $data[] = array('num' => utf8_decode('ESTRUCTURA'), 'contenido' => utf8_decode($construccion['Construction']['estructura']));
        if ($construccion['Construction']['muros'] != "")
            $data[] = array('num' => utf8_decode('MUROS'), 'contenido' => utf8_decode($construccion['Construction']['muros']));
        if ($construccion['Construction']['cubierta'] != "")
            $data[] = array('num' => utf8_decode('CUBIERTA'), 'contenido' => utf8_decode($construccion['Construction']['cubierta']));
        if ($construccion['Construction']['fachada'] != "")
            $data[] = array('num' => utf8_decode('FACHADA'), 'contenido' => utf8_decode($construccion['Construction']['fachada']));
        if ($construccion['Construction']['puertas'] != "")
            $data[] = array('num' => utf8_decode('PUERTAS'), 'contenido' => utf8_decode($construccion['Construction']['puertas']));
        if ($construccion['Construction']['ventanas'] != "")
            $data[] = array('num' => utf8_decode('VENTANAS'), 'contenido' => utf8_decode($construccion['Construction']['ventanas']));
        if ($construccion['Construction']['acabados_pisos'] != "")
            $data[] = array('num' => utf8_decode('ACABADOS PISOS'), 'contenido' => utf8_decode($construccion['Construction']['acabados_pisos']));
        if ($construccion['Construction']['cocina'] != "")
            $data[] = array('num' => utf8_decode('COCINA'), 'contenido' => utf8_decode($construccion['Construction']['cocina']));
        if ($construccion['Construction']['banio'] != "")
            $data[] = array('num' => utf8_decode('BAÑOS'), 'contenido' => utf8_decode($construccion['Construction']['banio']));

        $data1[] = array('cod' => utf8_decode($predio['Property']['codigo']),'num' => utf8_decode($construccion['Construction']['nombre']), 'contenido' => utf8_decode(strtoupper( $construccion['Construction']['estado_conservacion']) ));
        $data2[] = array('cod' => utf8_decode($predio['Property']['codigo']),'num' => utf8_decode($construccion['Construction']['nombre']), 'contenido' => utf8_decode($construccion['Construction']['vetustez']));
        $data3[] = array('cod' => utf8_decode($predio['Property']['codigo']),'num' => utf8_decode($construccion['Construction']['nombre']), 'contenido' => utf8_decode($construccion['Construction']['distribucion_interna']));
        $data4[] = array('num' => utf8_decode($predio['Property']['codigo']), 'nombre' => utf8_decode($construccion['Construction']['nombre']), 'contenido' => utf8_decode($construccion['Construction']['area']), 'unidad' => utf8_decode($construccion['Construction']['unidad_de_medida']));
        $data_conts[] = array('cont' => $conteo_const,'pred'=> utf8_decode($predio['Property']['codigo']), 'nombre' => utf8_decode($construccion['Construction']['nombre']), 'num' => '$' . number_format($construccion['Construction']['valor_adoptado'], 0, ',', '.'), 'unidad' => utf8_decode($construccion['Construction']['unidad_de_medida']));
        $conteo_const++;
        $total[] = array('ITEM' => utf8_decode($construccion['Construction']['nombre']), 'MAGNITUD' => $construccion['Construction']['area'], 'UNIDAD DE MEDIDA' => $construccion['Construction']['unidad_de_medida'], 'VALOR UNITARIO' => '$' . number_format($construccion['Construction']['valor_adoptado'], 0, ',', '.'), 'VALOR TOTAL' => '$' . number_format(($construccion['Construction']['area'] * $construccion['Construction']['valor_adoptado']), 0, ',', '.'));
        $valor_total+=$construccion['Construction']['area'] * $construccion['Construction']['valor_adoptado'];
    }

    foreach ($anexos as $anexo) {

        $data5[] = array('num' => utf8_decode($predio['Property']['codigo']), 'nombre' => utf8_decode($anexo['Annex']['nombre']), 'uso' => utf8_decode($anexo['Annex']['descripcion']), 'contenido' => utf8_decode($anexo['Annex']['area']), 'unidad' => $anexo['Annex']['unidad_de_medida']);
        $total[] = array('ITEM' => utf8_decode($anexo['Annex']['nombre']), 'MAGNITUD' => $anexo['Annex']['area'], 'UNIDAD DE MEDIDA' => $anexo['Annex']['unidad_de_medida'], 'VALOR UNITARIO' => '$' . number_format($anexo['Annex']['valor_adoptado'], 0, ',', '.'), 'VALOR TOTAL' => '$' . number_format(($anexo['Annex']['area'] * $anexo['Annex']['valor_adoptado']), 0, ',', '.'));
        $data_anex[] = array('cont' => $cont_anex,'pred' => utf8_decode($predio['Property']['codigo']), 'nombre' => utf8_decode($anexo['Annex']['nombre']), 'num' => '$' . number_format($anexo['Annex']['valor_adoptado'], 0, ',', '.'), 'unidad' => $anexo['Annex']['unidad_de_medida']);
        $cont_anex++;
        $valor_total+=$anexo['Annex']['area'] * $anexo['Annex']['valor_adoptado'];
    }
    if ($globalizado > 0)
        break;
}

$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 100, 'justification' => 'full'), 'contenido' => array('width' => 400, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2.1', 'contenido' => utf8_decode('ESTADO DE CONSERVACIÓN'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezTable(
        $data1, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('num' => array('width' => 250, 'justification' => 'full'), 'contenido' => array('width' => 250, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2.2', 'contenido' => utf8_decode('VETUSTEZ'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezTable(
        $data2, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
   // 'cols' => array('num' => array('width' => 250, 'justification' => 'full'), 'contenido' => array('width' => 250, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2.3', 'contenido' => utf8_decode('DISTRIBUCION INTERNA'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezTable(
        $data3, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('num' => array('width' => 250, 'justification' => 'full'), 'contenido' => array('width' => 250, 'justification' => 'full')),
        )
);
/////////AREAS
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2.4', 'contenido' => utf8_decode('<b>ÁREAS Y FUENTE</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

$pdf->ezTable(
        $data4, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('unidad' => array('width' => 125, 'justification' => 'full'), 'nombre' => array('width' => 125, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode('NOTA: LAS ÁREAS ESTA SUJETAS A VERIFICACIÓN POR PARTE DE LA ENTIDAD PETICIONARIA.'));

///ANEXOS
//
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '7.2.5', 'contenido' => utf8_decode('<b>ANEXOS</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezTable(
        $data5, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
   // 'cols' => array('uso' => array('width' => 100, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 100, 'justification' => 'full'), 'contenido' => array('width' => 100, 'justification' => 'full')),
        )
);
//Metodo de avaluo


$data = array();
$txt = "\n";
$metodo = utf8_decode(("MÉTODO DE AVALÚO: PARA LA DETERMINACIÓN DEL VALOR COMERCIAL DEL INMUEBLE EN ESTUDIO Y DE ACUERDO A LO ESTABLECIDO EN EL DECRETO NO. 1420 DEL 24 DE JULIO DE 1998, EXPEDIDO POR LA PRESIDENCIA DE LA REPÚBLICA, MINISTERIOS DE HACIENDA Y DESARROLLO Y SU CORRESPONDIENTE RESOLUCIÓN REGLAMENTARIA NO. 620 DEL 23 DE SEPTIEMBRE DE 2008, EXPEDIDA POR EL INSTITUTO GEOGRÁFICO AGUSTÍN CODAZZI, SE UTILIZARON LOS SIGUIENTES MÉTODOS:\n") );
if ($avaluoActual['Appraisal']['metodo_comparacion'] == 1) {
    $txt .= "MÉTODO DE COMPARACIÓN O DE MERCADO. ES LA TÉCNICA VALUATORIA QUE BUSCA ESTABLECER EL VALOR COMERCIAL DEL BIEN, A PARTIR DEL ESTUDIO DE LAS OFERTAS O TRANSACCIONES RECIENTES, DE BIENES SEMEJANTES Y COMPARABLES AL DEL OBJETO DE AVALÚO. TALES OFERTAS O TRANSACCIONES DEBERÁN SER CLASIFICADAS, ANALIZADAS E INTERPRETADAS PARA LLEGAR A LA ESTIMACIÓN DEL VALOR COMERCIAL. (EL DESARROLLO DE ESTE MÉTODO SE INCLUIRÁ COMO UN ANEXO).\n\n";
}

if ($avaluoActual['Appraisal']['expertos_avaluadores'] == 1) {
    $txt .= "COMO APOYO AL PROCESO VALUATORIO Y EN CONCORDANCIA CON EL ARTÍCULO 9° DE LA RESOLUCIÓN 620 DE 2008 SE ACUDE A  CONSULTAS A EXPERTOS AVALUADORES Y CONOCEDORES DEL MERCADO INMOBILIARIO EN LA ZONA DE LOCALIZACIÓN DEL INMUEBLE OBJETO DE AVALÚO. \n\n";
}

if ($avaluoActual['Appraisal']['metodo_reposicion'] == 1) {
    $txt .= "MÉTODO DE COSTO DE REPOSICIÓN. ES EL QUE BUSCA ESTABLECER EL VALOR COMERCIAL DEL BIEN OBJETO DE AVALÚO A PARTIR DE ESTIMAR EL COSTO TOTAL DE LA CONSTRUCCIÓN A PRECIOS DE HOY, UN BIEN SEMEJANTE AL DEL OBJETO DE AVALÚO, Y RESTARLE LA DEPRECIACIÓN ACUMULADA. AL VALOR ASÍ OBTENIDO SE LE DEBE ADICIONAR EL VALOR CORRESPONDIENTE AL TERRENO. (EL DESARROLLO DE ESTE MÉTODO SE INCLUIRÁ COMO UN ANEXO)\n\n";
}

if($avaluoActual['Appraisal']['metodo_comparacion'] != 1&&$avaluoActual['Appraisal']['expertos_avaluadores'] != 1&&$avaluoActual['Appraisal']['metodo_reposicion'] != 1){
    $txt="<b>NO HA SELECCIONADO METODO DE AVALÚO</b>";
    $metodo ="";
    
}

$pdf->ezText(utf8_decode($str)) ;
$data[] = array('num' => '8.', 'contenido' => utf8_decode('<b>MÉTODO DE AVALÚO</b>'));
$data[] = array('num' => '', 'contenido' => $metodo . "\n" . strtoupper(utf8_decode($txt)));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);


//ANALISIS DE ANTECEDENTS
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '9.', 'contenido' => utf8_decode('<b>ANÁLISIS DE ANTECEDENTES</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['antecedentes']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
///CONSSIDERACIONES GENERALES
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '10.', 'contenido' => utf8_decode('<b>CONSIDERACIONES GENERALES</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['consideraciones_generales']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);

//INVESTIGACION ECONOMICA
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '11.', 'contenido' => utf8_decode('<b>INVESTIGACIÓN ECONÓMICA</b>'));
$data[] = array('num' => '', 'contenido' => utf8_decode($avaluoActual['Appraisal']['investigacion_economica']));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
//VALORES ADOPTADOS
$pdf->ezText(utf8_decode($str));
$data = array();
$data[] = array('num' => '11.1', 'contenido' => utf8_decode('<b>VALORES ADOPTADOS</b>'));
$pdf->ezTable(
        $data, null, null, array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    'cols' => array('num' => array('width' => 50, 'justification' => 'full'), 'contenido' => array('width' => 450, 'justification' => 'full')),
        )
);
$pdf->ezTable(
        $data_11, null, 'Terreno', array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
   // 'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'num' => array('width' => 100, 'justification' => 'full'), 'valor' => array('width' => 100, 'justification' => 'full'), 'unidad' => array('width' => 125, 'justification' => 'full')),
        )
);

$pdf->ezTable(
        $data_conts, null, 'Construcciones', array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);

$pdf->ezTable(
        $data_anex, null, 'Anexos', array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
    //'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);

$pdf->ezNewPage();
$total[] = array('ITEM' => '', 'MAGNITUD' => '', 'UNIDAD DE MEDIDA' => '', 'VALOR UNITARIO' => 'Total', 'VALOR TOTAL' => '$' . number_format(($valor_total), 0, ',', '.'));
$pdf->ezText(utf8_decode($str));
$pdf->ezTable(
        $total, null, '12 RESULTADO DEL AVALUO', array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 2,
    'showLines' => 2,
    'shaded' => 0,
        //   'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);
$pdf->ezText(utf8_decode($str));
$V = new EnLetras();
$res = $V->ValorEnLetras($valor_total, "pesos");
$data = array(array("SON:$str" . ( strtoupper(utf8_decode($res) ) )));
$pdf->ezTable(
        $data, null, '', array(
    'fontSize' => 14,
    'titleFontSize' => 12,
    'width' => 500,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
        //   'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);


$pdf->ezText(utf8_decode($str));
$pdf->ezText(utf8_decode($str));
$pdf->ezText(utf8_decode($str));
$data = array(array("\n\n\n                             _______________________\n                             $usuario"));
$pdf->ezTable(
        $data, null, '', array(
    'fontSize' => 8,
    'titleFontSize' => 12,
    'width' => 300,
    'showHeadings' => 0,
    'showLines' => 2,
    'shaded' => 0,
        //   'cols' => array('cont' => array('width' => 50, 'justification' => 'full'), 'unidad' => array('width' => 100, 'justification' => 'full'), 'nombre' => array('width' => 100, 'justification' => 'full'), 'num' => array('width' => 125, 'justification' => 'full'), 'contenido' => array('width' => 125, 'justification' => 'full')),
        )
);

$pdf->ezStopPageNumbers(1, 1, 0);
//se comenta esta linea (la siguiente)para que no imprima el pdf y se puedan ver los errores.
//
$pdf->ezStream();
?>





<?php

function generar_carta($cod, $str, &$pdf, $start=true, $m_left=2.5, $m_right=2.5) {
    App::import('Vendor', 'ClassEzpdf', array('file' => 'pdf/class.ezpdf.php'));
    if ($pdf == NULL) {
        $pdf = new Cezpdf('LETTER');
    }
    if ($start) {
        $tmp = array(
            'b' => 'Trebuchet-Bold.afm'
            , 'i' => 'Trebuchet-Italic.afm'
            , 'bi' => 'Trebuchet-BoldItalic.afm'
            , 'ib' => 'Trebuchet-BoldItalic.afm'
            , 'bb' => 'Trebuchet-Bold.afm'
        );
        $pdf->setFontFamily('Trebuchet.afm', $tmp);
        $pdf->selectFont('fonts/Trebuchet.afm');

        //$pdf->ezSetCmMargins(5.5,5.5,4,4);

        $all = $pdf->openObject();
        $pdf->saveState();
        $pdf->addPngFromFile('img/encabezado_igac.png', 170, 710, 296, 65);
        $pdf->addPngFromFile('img/pie_igac.png', 10, 20, 590, 30);
        $pdf->restoreState();
        $pdf->closeObject();
        $pdf->addObject($all, 'all');
        $pdf->transaction('start');
    }

    $pdf->ezSetCmMargins(3.2, 2.5, $m_left, $m_right);

    $textOptions = array('justification' => 'full');
    $data = explode("\n", $str);
    $collecting = 0;
    foreach ($data as $d) {
        chop($d);
        if (strlen($d) && $d[0] == '#') {
            // comment, or new page request
            switch ($d) {
                case '#NP':
                    $pdf->ezNewPage();
                    break;
            }
        } else {
            $pdf->ezText($d, 8, $textOptions);
        }
    }
}
?>